<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 07.12.13
 * Time: 13:48
 */

class Tourism_Model_DbTable_Tours extends Engine_Db_Table
{
  protected $_rowClass = "Tourism_Model_Tour";

  public function getToursPaginator($params = array())
  {
    $select = $this->select();
    $ipp = isset($params['ipp']) && !empty($params['ipp']) ? $params['ipp'] : 10;
    $page = isset($params['page']) && !empty($params['page']) ? $params['page'] : 0;
    if (!empty($params['title'])) {
      $select->where('title LIKE ?', '%' . $params['title'] . '%');
    }
    if ($params['type']) {
      $select->where('type = ?', $params['type']);
    }
    $paginator = Zend_Paginator::factory($select);
    $paginator->setItemCountPerPage($ipp);
    $paginator->setCurrentPageNumber($page);
    return $paginator;
  }

  public function getTour($tour_id)
  {
    return $this->fetchRow(
      $this->select()
        ->where('tour_id = ?', $tour_id)
        ->limit(1)
    );
  }
}